package com.probiz.estore.system.service.impl;

import java.util.List;

import com.probiz.estore.common.model.system.SmsQueue;
import com.probiz.estore.core.service.impl.GenericManagerImpl;
import com.probiz.estore.core.util.I18nUtil;
import com.probiz.estore.system.service.SmsQueueManager;
import com.probiz.estore.system.dao.SmsQueueDao;


/**
 * Manager implementation for SmsQueue, responsible for business processing, and communicate between web and persistence layer.
 */
public class SmsQueueManagerImpl extends GenericManagerImpl<SmsQueue> implements SmsQueueManager {

	private SmsQueueDao smsQueueDao = null;

	/**
	 * @param smsQueueDao
	 *            the smsQueueDao to set
	 */
	public void setSmsQueueDao(SmsQueueDao smsQueueDao) {
		this.smsQueueDao = smsQueueDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#init()
	 */
	@Override
	protected void initManager() {
		dao = smsQueueDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preDelete(java.lang.Object)
	 */
	@Override
	protected void preDelete(SmsQueue entity) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preSave(java.lang.Object)
	 */
	@Override
	protected void preSave(SmsQueue entity) {

	}
	
	/**
	 * 创建短信队列
	 * @param modelContent 短信内容模板
	 * @param phoneNumbers 手机号码
	 * @param customerNames 客户名称 暂不处理
	 * 
	 * */
	public void addSmsQueue(String modelContent,String phoneNumbers,String customerNames) {
		SmsQueue sms = new SmsQueue();
		sms.setSmsContent(modelContent);
		sms.setPhoneNumbers(phoneNumbers);
		sms.setCustomerNames(customerNames);
		String status = I18nUtil.getInstance().getMessage("smsQueue.status0");
		sms.setSendStatus(status);
		sms.setStatus(SmsQueue.SMS_NOSEND);		
		sms.setSendMaxNum(0);
		dao.save(sms);
	}
	
	/**
	 * 查询出前maxPage条用于发送
	 * 
	 * */
	public List<SmsQueue> getSmsQueueToSend(int maxPage, int sendMaxNum){
		return smsQueueDao.getSmsQueueToSend(maxPage, sendMaxNum);
	}

}
